// pages/xq/index.js
const app = getApp()
import {
  urls
} from '../../api/urls'
import {
  share_by_property,
  get_sys_broadcast
} from '../../api/request'

Page({
  data: {
    font_size: '',
    key: '', // 系统查询关键字
    info: {},
    property_code: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      key: options.key,
      property_code: options.property_code
    })
    this.share_by_property(this.data.property_code)
    this.sys_broadcast(this.data.key)
  },

  //小程序分享信息查询
  share_by_property(property_code) {
    var data = {
      para: [property_code]
    }
    share_by_property(data).then(res => {
      app.globalData.share_title = res.data[0].SHARE_TITLE
      app.globalData.share_img_url = res.data[0].SHARE_IMG_URL
      app.globalData.signature_name=wx.getStorageSync('signature_name'),

      this.user_log_record(app.globalData.cur_my_openid, app.globalData.cur_my_name, '', '', app.globalData.cur_property_code,
        app.globalData.cur_property_name, '1', '1', '1')
    })
  },

  onReady: function () {

  },

  onShow: function () {},


  //获取系统公告
  sys_broadcast(m_key) {
    var data = {
      para: [m_key]
    }
    get_sys_broadcast(data).then(res => {
      this.setData({
        info: res.data[0] //返回数据
      })
      wx.setNavigationBarTitle({
        title: '业主我当家',
      })
      //格式替换
      var article_content = this.data.info
      article_content.CONTENT = article_content.CONTENT.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block"')
      article_content.CONTENT = article_content.CONTENT.replace(/<section/g, '<div')
      article_content.CONTENT = article_content.CONTENT.replace(/\/section>/g, '\div>');
      //      article_content.CONTENT = article_content.CONTENT.replace(/\n/g, '<br>');

      this.setData({
        info: article_content,
        font_size: wx.getStorageSync('font_size')
      })


    })
  },

  //字体控制
  font_show(e) {
    var m_size = e.currentTarget.dataset.size;
    this.setData({
      font_size: 'show_size_' + m_size
    })
    wx.setStorageSync('font_size', this.data.font_size)
  },

  //分享朋友圈
  onShareTimeline: function () {
    return {
      title: app.globalData.signature_name + '《业主我当家》微信小程序：' +this.data.info.TITLE,
      query: 'key=' + this.data.key + '&property_code=' + this.data.property_code,
      imageUrl: 'https://yz.2alive.cn/image/logo.png',
    }
  },


  // 用户点击右上share角分享
  onShareAppMessage: function () {
    return {
      title: app.globalData.signature_name + '《业主我当家》微信小程序：' + this.data.info.TITLE,
      path: '/pages/my_show/index?key=' + this.data.key + '&property_code=' + this.data.property_code,
      imageUrl: app.globalData.share_img_url,
    }
  },

})